<template>
  <a-row>
    <a-col span="24">
      <a-card title="待办任务">
        <div class="toDoTaskBox">
          <div v-for="item in toDoList" class="item" :key="item.id">
            <div class="item-title">
              <span>{{item.title}}</span>
              <span class="desc">{{ item.desc }}</span>
            </div>
            <div class="item-content">
              <div v-for="children in item.children" class="item-content-children" :key="children.id">
                <template v-if="children.show">
                  <div  style="cursor: pointer;">
                    <div class="item-content-top">
                      <!-- <div class="item-content-top-desc">{{children.title}}</div> -->
                      <div class="item-content-top-data">
                        <span>{{(Number(children.data || 0)).toLocaleString()}}</span>
                      </div>
                    </div>
                    <div class="item-content-bottom">{{children.desc}}</div>
                  </div>
                </template>
              </div>
            </div>
          </div>
        </div>
      </a-card>
    </a-col>
  </a-row>
</template>

<script setup lang="ts" name="toDoList">
import { ref, onMounted } from "vue";
import * as api from '@/api/index'
import { formatDates } from "@/uilts/uilts-core";
const toDoList = ref([
  {
    id: 2,
    title: '开发面板',
    desc: '任务开发进度48%',
    children: [
      {
        id: 21,
        route: '/note/admin-limit',
        title: '已完成',
        data: '0',
        show: true,
        desc: `已完成`,
        query: {
          auditStatus: '0' // 查询待审核的活动
        }
      },
      {
        id: 22,
        route: '/note/admin-limit',
        title: '进行中',
        desc: `进行中`,
        data: 60,
        show: true
      },
      {
        id: 23,
        route: '/note/admin-limit',
        title: '已暂停',
        desc: `已暂停`,
        data: 60,
        show: true
      },
      {
        id: 24,
        route: '/note/admin-limit',
        title: '已逾期',
        desc: `已逾期`,
        data: 60,
        show: true
      }
    ]
  },
  {
    id: 3,
    title: '博客面板',
    desc: '当前文章总量：2443',
    children: [
      {
        id: 31,
        route: '/note/admin-limit',
        title: '审核通过',
        data: '100',
        show: true,
        desc: `审核通过`,
        query: {
          auditStatus: '0' // 查询待审核的活动
        }
      },
      {
        id: 32,
        route: '/note/admin-limit',
        title: '审核中',
        desc: `审核中`,
        data: 60,
        show: true
      },
      {
        id: 33,
        route: '/note/admin-limit',
        title: '草稿箱',
        desc: `草稿箱`,
        data: 60,
        show: true
      },
      {
        id: 34,
        route: '/note/admin-limit',
        title: '已冻结',
        desc: `已冻结`,
        data: 60,
        show: true
      }
    ]
  },
  {
    id: 4,
    title: '用户面板',
    desc: '当前用户总数：2443',
    children: [
      {
        id: 41,
        route: '/note/admin-limit',
        title: '活动用户',
        data: '100',
        show: true,
        desc: `活动用户`,
        query: {
          auditStatus: '0' // 查询待审核的活动
        }
      },
      {
        id: 42,
        route: '/note/admin-limit',
        title: '冻结用户',
        desc: `冻结用户`,
        data: 60,
        show: true
      },
      {
        id: 43,
        route: '/note/admin-limit',
        title: '封禁用户',
        desc: `封禁用户`,
        data: 60,
        show: true
      }
    ]
  },
  {
    id: 1,
    title: 'API面板',
    desc: 'API使用占比100%',
    children: [
      {
        id: 11,
        route: '/note/admin-limit',
        title: '活动中',
        data: '0',
        show: true,
        desc: `活动中`,
        query: {
          auditStatus: '0' // 查询待审核的活动
        },
        toLinkRole: true // 是否有活动管理页面权限
      },
      {
        id: 12,
        route: '/note/admin-limit',
        title: '已停用',
        data: 60,
        show: true,
        desc: `已停用`
      }
    ]
  }
])
onMounted(() => {
  api.admin.getPanelData({}).then((res: BaseResponse<any>) => {
    console.log(res, '111')
    let { apiPanel, blogPanel, progressPanel, userPanel } = res.body
    toDoList.value[3].desc = `API使用占比${(apiPanel.activeApi / apiPanel.totalApi * 100).toFixed(2)}%`
    toDoList.value[3].children[0].data = apiPanel.activeApi
    toDoList.value[3].children[1].data = apiPanel.stopApi

    toDoList.value[0].desc = `任务开发进度${(progressPanel.finishProgress / progressPanel.totalProgress * 100).toFixed(2)}%`
    toDoList.value[0].children[0].data = progressPanel.finishProgress
    toDoList.value[0].children[1].data = progressPanel.underwayProgress
    toDoList.value[0].children[2].data = progressPanel.stopProgress
    toDoList.value[0].children[3].data = progressPanel.overdueProgress

    toDoList.value[1].desc = `当前文章总量：${blogPanel.totalBlog}`
    toDoList.value[1].children[0].data = blogPanel.approveBlog
    toDoList.value[1].children[1].data = blogPanel.reviewBlog
    toDoList.value[1].children[2].data = blogPanel.draftsBlog
    toDoList.value[1].children[3].data = blogPanel.freezeBlog

    toDoList.value[2].desc = `当前用户总数：${userPanel.totalUser}`
    toDoList.value[2].children[0].data = userPanel.activeUser
    toDoList.value[2].children[1].data = userPanel.freezeUser
    toDoList.value[2].children[2].data = userPanel.bannedUser
  })
})
</script>

<style lang="less" scoped>
.toDoTaskBox{
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  .item{
    width: 33%;
    padding: 24px;
    box-sizing: border-box;
    .item-title{
      display: flex;
      justify-content: space-between;
      padding: 0px 24px;
      height: 54px;
      // padding-left: 24px;
      line-height: 54px;
      font-size: 20px;
      font-weight: 700;
      border: 1px solid #999;
      border-top-right-radius: 4px;
      border-top-left-radius: 4px;
      .desc {
        font-size: 14px;
        font-weight: 400;
        color: rgb(231, 9, 24);
      }
    }
    .item-content{
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      border: 1px solid #c9c9c9;
      border-bottom-left-radius: 4px;
      border-bottom-left-radius: 4px;
      padding: 24px;
      box-sizing: border-box;
      .item-content-children{
        width: 45%;
        .item-content-top{
          border-bottom: 1px solid #c9c9c9;
          .item-content-top-desc{
            color: #b9b9b9;
            font-size: 18px;
          }
          .item-content-top-data{
            font-size: 30px;
            font-weight: 700;
            color: #E70918;
          }
        }
         .item-content-bottom{
            color: #c9c9c9;
            padding: 8px 0px;
            font-size: 16px;
         }
      }
    }
  }
}
</style>
